<?php
error_reporting(E_ALL);
	$p_id  = isset($_GET["id"]);
	if($p_id){
				$sql     = "
				SELECT clients.fname,clients.lname,project_category.cat_title,projects.date_started,projects.p_id,projects.p_title,projects.p_url,projects.ftp_address,projects.ftp_username,projects.ftp_password,projects.host_name,projects.host_username,projects.host_password
				FROM projects 
				INNER JOIN clients ON clients.c_id = projects.c_id
				LEFT OUTER JOIN project_category ON project_category.cat_id = projects.cat_id 
				WHERE p_id='$p_id' 
				LIMIT 1";
		$result  = mysql_query($sql) or die(mysql_error());
		$row     = mysql_fetch_assoc($result);
		
		print '<h3>'.$row['p_title'].' - <a href="'.$row['p_url'].'" title="View URL" target="_blank">'.$row['p_url'].'</a></h3><br />';
		print '<h4>Client is <b>'.$row['fname'].' '.$row['lname'].'</b> and project was started on: <b>'. date('m/d/y', strtotime($row['date_started'])).' </b></h4>';
		print '<h4>Project has been marked as a(n) <i>'.$row['cat_title'].'</i> site/project';
		
		$sql_pages    = "SELECT pages.page_name FROM pages WHERE p_id=".$row["p_id"]."";
		$query_pages  = mysql_query($sql_pages) or die(mysql_error());
		print "<h4>Pages belonging to the project: <b>";
		while($row_pages = mysql_fetch_array($query_pages)){
			print $row_pages['page_name'].', ';
		}
		print "
		<fieldset>
			<legend>FTP Information</legend>
			<b>FTP Address:</b>" . $row['ftp_address'] . "<br />
			<b>FTP Username:</b>" . $row['ftp_username'] . "<br />
			<b>FTP Password:</b> <i>" . $row['ftp_password'] . "</i><br />
		</fieldset>
		<fieldset>
			<legend>Host Information</legend>
			<b>Host Name:</b> " . $row['host_name'] . "<br />
			<b>Username:</b> " . $row['host_username'] . "<br />
			<b>Password:</b> <i>" . $row['host_password'] . "</i><br />
		</fieldset>
";
		include "setstatus.php";
	}else{
?>
<h3>Viewing All Open Projects</h3>
<h4>Follow the view column to view project details</h4>
<table>
	<thead>
		<tr>
			<th>Project Title</th>
			<th>Type of Project</th>
			<th>Client</th>
			<th>View</th>
		</tr>
	</thead>
	<tbody>
<?php
	$sql    = "SELECT project_category.cat_title,projects.* FROM projects LEFT OUTER JOIN project_category ON project_category.cat_id = projects.cat_id";
	$query  = mysql_query($sql) or die(mysql_error());
	while($row = mysql_fetch_array($query)){
		print '<tr>'; 
			print '<td>'.$row['p_title'].'</td>'; 
			print '<td>'.$row['cat_title'].'</td>'; 
			print '<td>'.$row['p_title'].'</td>'; 
			print '<td class="center"><a href="?c=viewprojects&id='.$row['p_id'].'" title="View Project"><img src="images/page_edit.png" alt="Edit entry!" /></a></td>';
		print '</tr>';
	}
?>
	</tbody>
</table>


<?php } // end if else ?>